﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SocialKit.LightRest
{
    /// <summary>
    /// Provides methods for convinenet usages of SocialKit.LightRest.RestClient.
    /// </summary>
    public static class HttpMethodExtensions
    {
        /// <summary>
        /// Gets the content of specified Uri with specified QueryStrings.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri to be requested.</param>
        /// <param name="queryString">The HttpQueryString to be combiled with the Uri.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, Uri uri, HttpQueryString queryString)
        {
            uri = HttpQueryString.MakeQueryString(uri, queryString);

            return client.Send(HttpMethod.GET, uri);
        }

        /// <summary>
        /// Gets the content of specified Uri with specified query values.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri to be requested.</param>
        /// <param name="queryString">The query values to be sent.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, Uri uri, IEnumerable<KeyValuePair<string, string>> queryString)
        {
            uri = HttpQueryString.MakeQueryString(uri, queryString);

            return client.Send(HttpMethod.GET, uri);
        }

        /// <summary>
        /// Gets the content of specified Uri.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri to be requested.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, Uri uri)
        {
            return client.Send(HttpMethod.GET, uri);
        }

        /// <summary>
        /// Gets the content of specified Uri string with specified QueryStrings.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri string to be requested.</param>
        /// <param name="queryString">The HttpQueryString to be combiled with the Uri.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, string uri, HttpQueryString queryString)
        {
            return Get(client, new Uri(uri, UriKind.RelativeOrAbsolute), queryString);
        }

        /// <summary>
        /// Gets the content of specified Uri string with specified query values.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri string to be requested.</param>
        /// <param name="queryString">The query values to be sent.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, string uri, IEnumerable<KeyValuePair<string, string>> queryString)
        {
            return Get(client, new Uri(uri, UriKind.RelativeOrAbsolute), queryString);
        }

        /// <summary>
        /// Gets the content of specified Uri string.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri string to be requested.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client, string uri)
        {
            return client.Send(HttpMethod.GET, uri);
        }

        /// <summary>
        /// Gets the content of the BaseAddress of this SocialKit.LightRest.RestClient instance.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Get(this RestClient client)
        {
            return client.Send(HttpMethod.GET);
        }

        /// <summary>
        /// Gets the headers of specified Uri.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri to be requested.</param>
        /// <returns>A response message does not contains http body.</returns>
        public static HttpResponseMessage Head(this RestClient client, Uri uri)
        {
            return client.Send(HttpMethod.HEAD, uri);
        }

        /// <summary>
        /// Gets the headers of specified Uri string.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri string to be requested.</param>
        /// <returns>A response message does not contains http body.</returns>
        public static HttpResponseMessage Head(this RestClient client, string uri)
        {
            return client.Send(HttpMethod.HEAD, uri);
        }

        /// <summary>
        /// Posts the request http body content of the specified creator to the Uri.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri used to post http body content.</param>
        /// <param name="creator">A request http body creator.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Post(this RestClient client, Uri uri, IHttpContentCreator creator)
        {
            return client.Send(HttpMethod.POST, uri, creator);
        }

        /// <summary>
        /// Posts the request http body content of the specified creator to the Uri string.
        /// </summary>
        /// <param name="client">The SocialKit.LightRest.RestClient.</param>
        /// <param name="uri">The Uri string used to post http body content.</param>
        /// <param name="creator">A request http body creator.</param>
        /// <returns>A response message.</returns>
        public static HttpResponseMessage Post(this RestClient client, string uri, IHttpContentCreator creator)
        {
            return client.Send(HttpMethod.POST, uri, creator);
        }
    }
}